//
//  GoodListCollectionViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/5/12.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "GoodListCollectionViewCell.h"

@interface GoodListCollectionViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UIButton *buyBtn;

@end

@implementation GoodListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        
        _imgView = [UIImageView new];
        _infoLabel = [UILabel new];
        _buyBtn = [UIButton new];
        
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
//        _imgView.backgroundColor = getColor(@"f1f2f6");
        
        _infoLabel.numberOfLines = 2;
        _infoLabel.font = DEF_FontSize_12;
        
        [_buyBtn setTitle:@"立即购买" forState:UIControlStateNormal];
        [_buyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _buyBtn.layer.masksToBounds = YES;
        _buyBtn.titleLabel.font = DEF_FontSize_12;
        _buyBtn.backgroundColor = getColor(mainColor);
        _buyBtn.userInteractionEnabled = NO;
        
        [self.contentView addSubview:_imgView];
        [self.contentView addSubview:_infoLabel];
        [self.contentView addSubview:_buyBtn];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imgView.frame = CGRectMake(0, 6, self.frame.size.width, self.frame.size.height*.5);
    _infoLabel.frame = CGRectMake(0, CGRectGetMaxY(_imgView.frame), self.frame.size.width, self.frame.size.height - CGRectGetMaxY(_imgView.frame) - 28);
    _buyBtn.frame = CGRectMake(0, self.frame.size.height - 28, self.frame.size.width/2., 20);
    _buyBtn.layer.cornerRadius = 10;
    _buyBtn.center = CGPointMake(self.frame.size.width/2., _buyBtn.center.y);
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    [_imgView sd_setImageWithURL:[NSURL URLOffsetIPWithString:dataDictionary[@"c_first_figure"]]];
    NSString *temp = [NSString stringWithFormat:@"%@\n价格 ¥%@",dataDictionary[@"c_name"],dataDictionary[@"c_unit_price"]];
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:temp];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:3];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    _infoLabel.attributedText = attributedString;
    _infoLabel.textAlignment = NSTextAlignmentCenter;
}

@end
